//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_progbarcall.sqf"
#include "x_setup.sqf"

private ["_captime", "_wf", "_curcaptime", "_disp", "_control", "_backgroundControl", "_maxWidth", "_position", "_newval"];
PARAMS_1(_wf);
disableSerialization;
_captime = _wf getVariable QGVAR(CAPTIME);
_curcaptime = _wf getVariable QGVAR(CURCAPTIME);
_curside = _wf getVariable QGVAR(SIDE);
_disp = __uiGetVar(DPROGBAR);
_control = _disp displayCtrl 3800;
_backgroundControl = _disp displayCtrl 3600;
_maxWidth = (ctrlPosition _backgroundControl select 2);
_position = ctrlPosition _control;
_newval = if (_curside != GVAR(own_side_trigger_alt)) then {((_maxWidth * _curcaptime / _captime) min _maxWidth) max 0.02} else {_maxWidth};
_position set [2, _newval];
_r = 1 - (_newval * 2.777777);
_g = _newval * 2.777777;
_control ctrlSetPosition _position;
//_control ctrlSetBackgroundColor (if !(_wf getVariable QGVAR(STALL)) then {[0.543, 0.5742, 0.4102, 0.8]} else {[1, 1, 0, 0.8]});
_control ctrlSetBackgroundColor (if !(_wf getVariable QGVAR(STALL)) then {[_r, _g, 0, 0.8]} else {[1, 1, 0, 0.8]});
_control ctrlCommit 3;